<template>
  <div class="web">
    <div class="webLeft">
      <menuleft
        :menuList="menuList"
        @handleMenu="handleMenu"
        :menuFlag="menuFlag"
      />
    </div>
    <div class="webRight">
      <ArticleList
        ref="articleList"
        :moduleId="menuFlag"
        :menuList="menuList"
      />
    </div>
  </div>
</template>

<script>
import ArticleList from "./components/articleList";
import { getExchangeList } from "../../../service/Api";
import bus from "@/components/bus";

export default {
  name: "exchange",
  components: { ArticleList },
  data() {
    return {
      menuFlag: "",
      menuList: [
        {
          name: "内部交流",
          id: "0",
          children: [],
        },
      ],
    };
  },
  watch: {
    "$route.query"(n, o) {
      this.menuFlag = this.$route.query.menuFlag;
    },
    menuFlag(n, o) {
      this.menuFlag = n;
    },
  },
  mounted() {
    //监听公司交流内容的删除事件
    bus.$on("updateList", (val) => {
      console.log(val);
      this.$refs.articleList.getArticleList();
    });
    this.getExchangeList();
  },
  methods: {
    getExchangeList() {
      getExchangeList().then((res) => {
        let moduleName = res.data;
        if (this.$route.query.menuFlag) {
          this.menuFlag = this.$route.query.menuFlag;
        } else {
          this.menuFlag = res.data[0].id.toString();
        }
        let obj = {};
        moduleName.forEach((item, index) => {
          obj = {
            id: item.id,
            name: item.moduleName,
            flag: true,
          };
          this.menuList[0].children.push(obj);
          this.menuList = [...this.menuList];
        });
        console.log(this.menuList);
      });
    },
    handleMenu(id) {
      // 点击左侧切换
      console.log(this.menuList, "fff", id);
      this.menuFlag = id;
    },
  },
};
</script>

<style scoped>
@import "../../../styles/common.css";
</style>